from get_data import *
from first_data import *
from get_direction import *
from infer import *
from myserial import *
import os

if __name__=='__main__':
    '''
    os.system("sudo chmod -R 777 /dev/ttyTHS0")
    os.system("zhs")
    '''
    model_file = "./best_model"
    model = load_model(model_file)

    '''img
    #图片路径
    photo_file = "72.png"
    #infer
    infer(photo_file)
    out_img = './output/'+'visualize_'+photo_file
    print(out_img)
    #读取图像
    img = get_data(out_img)
    #预处理图像
    img_target = first_data(img)
    #获取前进方向
    direction = get_direction(img_target,img)
    '''
    
    '''camera
    pipeline = camera_init()
    while True:
        get_carema(pipeline)
    '''

    #video
    video_file = "./demo.avi"
    cap = video_init(video_file)
    while True:
        frame = get_video(cap)
        cv2.imwrite("1.png",frame)
        infer("1.png",model)
        out_img = './output/'+'visualize_1.png'
        #读取图像
        img = get_data(out_img)
        #预处理图像
        img_target = first_data(img)
        #获取前进方向
        direction = get_direction(img_target,img)
        #send_data
        serial_write(direction)



